package com.shuangdj.databinding.adapter;

import android.content.Context;
import android.databinding.DataBindingUtil;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.shuangdj.databinding.R;
import com.shuangdj.databinding.bean.TestModel;
import com.shuangdj.databinding.databinding.ItemMainBinding;
import com.shuangdj.databinding.presenter.TestPresenter;

import java.util.List;

/**
 * Created by linxiaoke on 17/4/10.
 */

public class TestAdapter extends TAdapter<TestModel> {

    public TestAdapter(Context context, List<TestModel> testModels) {
        super(context, testModels);
    }

    @Override
    public int getCount() {
        return tList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ItemMainBinding binding;
        if (convertView == null) {
            binding = DataBindingUtil.inflate(LayoutInflater.from(context),
                    R.layout.item_main, parent, false);
            convertView = binding.getRoot();
            convertView.setTag(binding);
        } else {
            binding = (ItemMainBinding) convertView.getTag();
        }
        binding.setTest(tList.get(position));
        binding.setTestPresenter(new TestPresenter());
        binding.executePendingBindings();
        return convertView;
    }

}
